﻿using Appliaction.Dto.Base_Manage;
using Appliaction.IAppServices.Base_Manage;
using AutoMapper;
using Domain.Entitys.Base_Manage;
using Domain.IRepositorys.Base_Manage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Base_Manage
{
    public class DeptService : IDeptService
    {
        private readonly IDeptRepository deptRepository;
        private readonly IMapper mapper;

        public DeptService(IDeptRepository deptRepository,IMapper mapper)
        {
            this.deptRepository = deptRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="deptAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> DeptAddAsync(DeptAddDto deptAddDto)
        {
            Sys_Dept dept = mapper.Map<Sys_Dept>(deptAddDto);
            return await deptRepository.DeptAddAsync(dept);
        }

        /// <summary>
        /// 逻辑删除部门信息
        /// </summary>
        /// <param name="dept_id"></param>
        /// <param name="del"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> DeptDeleteAsync(DeptDelDto deptDelDto)
        {
            Sys_Dept dept = mapper.Map<Sys_Dept>(deptDelDto);
            return await deptRepository.DeptDeleteAsync(dept);
        }

        /// <summary>
        /// 查询全部部门
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Sys_Dept>> DeptOptAsync()
        {
            return deptRepository.DeptOptAsync();
        }
        
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="deptUpdateDto"></param>
        /// <returns></returns>
        public async Task<int> DeptUpdateAsync(DeptUpdateDto deptUpdateDto)
        {
            Sys_Dept dept = mapper.Map<Sys_Dept>(deptUpdateDto);
            return await deptRepository.DeptUpdateAsync(dept);
        }

        /// <summary>
        /// 根据部门名称和负责人分页查询信息
        /// </summary>
        /// <param name="dept_name"></param>
        /// <param name="leader"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Sys_Dept> GetDepts(string dept_name, string leader, int currentPage, int pageSize)
        {
            return deptRepository.GetDepts(dept_name, leader, currentPage, pageSize);
        }
        /// <summary>
        /// 根据部门名称和负责人分页查询总个数
        /// </summary>
        /// <param name="dept_name"></param>
        /// <param name="leader"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int GetDeptsCount(string dept_name, string leader)
        {
            return deptRepository.GetDeptsCount(dept_name, leader);
        }

        /// <summary>
        /// 查询部门信息及其子级部门
        /// </summary>
        /// <returns></returns>
        public List<Sys_Dept_Trees> Get_Dept_Trees(string name)
        {
            return deptRepository.Get_Dept_Trees(name);
        }
    }
}
